<template>
  <div class="book-reader">
    <div id="read"></div>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import Epub from 'epubjs'

  global.epub = Epub

  export default {
    computed: {
      ...mapGetters(['fileName'])
    },
    mounted () {
      this.$store.dispatch('setFileName', this.$route.params.fileName.split('|').join('/')).then(() => {
        this.initEpub()
      })
    },
    methods: {
      initEpub () {
        const url = `http://localhost:8081/epub/${this.fileName}.epub`
        this.book = new Epub(url)
        this.rendition = this.book.renderTo('read', {
          width: innerWidth,
          height: innerHeight,
          method: 'default'
        })
      }
    }
  }
</script>

<style scoped>

</style>
